package org.onion.pattern.kit.validation.annotation;

import org.onion.pattern.kit.validation.annotation.validator.ElementsValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 验证值必须在给定值的范围之中
 *
 */
@Documented
@Constraint(validatedBy = {ElementsValidator.class})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Repeatable(Within.ElementsList.class)
public @interface Within {

    String message() default "元素不匹配";

    String[] value() default {};

    String[] strEle() default {};

    int[] intEle() default {};

    long[] longEle() default {};

    short[] shortEle() default {};

    float[] floatEle() default {};

    double[] doubleEle() default {};

    char[] charEle() default {};

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
    @Retention(RUNTIME)
    @Documented
    @interface ElementsList {
        Within[] value();
    }

}
